package meatslope2.gameengine.gameobjects.model;

import meatslope2.gameengine.components.Component;
import meatslope2.gameengine.engine.Engine.Time;
import meatslope2.gameengine.primatives.Vector2;

/**
 * Base class defining the core set of information necessary to render (and move
 * an object on the screen)
 * 
 */
public class MovableGameObject extends DrawableGameObject
{
	// ===========================================================
	// Members
	// ===========================================================
	
	//Previous Position
	protected final Vector2 prevPosition = new Vector2();
	
    //Velocity
    protected final Vector2 velocity = new Vector2(0,0);

    //Components
    protected Component[] components = new Component[0];
    
	// ===========================================================
	// Getters/Setters
	// ===========================================================
    
	public Vector2 getPrevPosition()
	{
		return this.prevPosition;
	}
	
	public Vector2 getVelocity()
	{
		return this.velocity;
	}
    
	// ===========================================================
	// Constructors
	// ===========================================================
    
    public MovableGameObject(Sprite sprite, int width, int height)
    {
    	super(sprite, width, height);
    }
    
	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================
    
    private final int speed = 100;
    public void update()
    { 	
    	float deltaTime = Time.getDeltaTime();
    	position.add(velocity.x * deltaTime * speed, velocity.y * deltaTime * speed);
    	
    	for(int i = 0; i < components.length; i++)
    		components[i].update();
    	
    	this.prevPosition.set(position);
    }
}